<template>
    <div class="e-table billList">
        <div class="top">
            <div class="left">
                <div class="listTop">
                    <el-button
                        size="small"
                        class="btn-greenYellow"
                        @click="openAddDialog"
                    >
                        新增</el-button
                    >
                </div>
            </div>
            <div class="right">
                <div  class="right-div1">
                    <el-input
                        placeholder="请输入关键字"
                        size="small"
                        v-model="pagination.query"
                        @blur="search"
                    >
                        <i slot="suffix" class="el-input__icon el-icon-search" @click="search"></i>
                    </el-input>
                </div>
                <div>
                    <el-button
                        size="small"
                        style="background: #2e61d7; color: #fff"
                        @click="heightSharch"
                        >高级搜索
                    </el-button>
                </div>
            </div>
        </div>
        <el-table
            class="table"
            :data="tableData"
            border
            style="width: 100%"
            highlight-current-row
        >
            <el-table-column label="设备类别" prop="categoryName" min-width="200" show-overflow-tooltip>
             <!-- <template slot-scope="{ row }" >
                <span @click="tableDbShow(row)">{{row.categoryName}}</span>
            </template> -->
            </el-table-column>
            <el-table-column
                prop="quantityValue"
                label="每公里/小时数"
                width="200"
            >
            </el-table-column>
            <el-table-column
                prop="tenderUser"
                label="保养周期"
                width="200"
            >
                <template slot-scope="{ row }">
                    <span> {{ row.maintenanceCycle ? maintenanceCycle.find(x=>x.value === row.maintenanceCycle).label :''}} </span>
                </template>
            </el-table-column>
            <el-table-column
                prop="orgName"
                label="机构"
                min-width="200"
                show-overflow-tooltip
            >
            </el-table-column>
            <el-table-column
                prop="isEnable"
                label="是否启用"
                width="200"
            >
                 <template slot-scope="{ row }">
                    <span> {{ JSON.parse(row.isEnable) ? '是' : '否' }} </span> <!-- true 是  false 否 -->
                </template>
            </el-table-column>
        </el-table>
        <ComPagination
            :total="totalPage"
            :pageSize.sync="pagination.limit"
            :currentPage.sync="pagination.page"
            @currentChange="listByEntity"
            @sizeChange="listByEntity"
            class="bottomSetting"
        />
    </div>
</template>

<script>
import request from '@/api/equip/equipPlan.js'
import ComPagination from '@/components/pagination/pagination.vue'
import { mapState, mapMutations } from 'vuex'
import { advanceSearch } from '@/utils/common.js'
export default {
    data () {
        return {
            tableData: [],
            loading: false,
            pagination: {
                'category': '',
                'limit': 20,
                'organization': '',
                'page': 1,
                'query': ''
            },
            totalPage: 0, //总页数
        }
    },
    components: {
        ComPagination
    },
    computed: {
        statusLable () {
            return param=> {
                const state =  this.$store.state.equip.equipData.state
                const obj = state.find(x=>x.value === param)
                return (obj ?  obj.label :  '')
            }
        },
        ...mapState({
            maintenanceCycle: state=>state.equip.equipData.maintenanceCycle, //保养周期
        })
    },
    created () {

    },
    mounted () {
        this.getList()
    },
    methods: {
        ...mapMutations(['setSearchData']),
        //获取列表
        getList () {
            request.maintenancePlanList(this.pagination).then(res=>{
                this.tableData = res.list
                this.totalPage = res.totalCount
            })
        },
        //分页查询
        listByEntity () {
            this.getList()
        },
        //新增
        openAddDialog () {
            this.$router.push('/maintenancePlanAdd')
        },
        search () {
            this.getList()
        },
        heightSharch () {
            advanceSearch('/equipPlanHeightSearch').then(res => {
                this.pagination = res.equipSearchData
                this.getList()
                this.clearData()
            })
        },
        //清空高级搜索的数据
        clearData () {
            this.pagination = {
                'category': '',
                'limit': 20,
                'organization': '',
                'page': 1,
                'query': ''
            }
            this.setSearchData({ equipSearchData: this.pagination })
        },
        //查看
        tableDbShow (row) {
            this.$router.push({
                path: '/maintenancePlanAdd',
                query: { billid: row.billId }
            })
        },
    }
}
</script>

<style lang="scss" scoped>

</style>
